package com.chenfeng.ego.search.controller;

import java.io.IOException;

import javax.annotation.Resource;

import org.apache.solr.client.solrj.SolrServerException;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.chenfeng.ego.commons.pojo.SearchResult;
import com.chenfeng.ego.search.service.SolrService;

@Controller
public class SolrController
{

	@Resource
	private SolrService service;

	@RequestMapping("solr/init")
	@ResponseBody
	public String myInit()
	{
		try
		{
			return service.initSolr();
		} catch (SolrServerException | IOException e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}

	// solr要查询的数据
	@RequestMapping("solr/search")
	@ResponseBody
	public SearchResult search(String q, int page, int rows)
	{
		try
		{
			return service.selByQ(q, page, rows);
		} catch (SolrServerException e)
		{
			e.printStackTrace();
		}
		return null;
	}
}
